#__author__=='qustl_000'
#-*- coding: utf-8 -*-

import Bayes
import os
import re
from numpy import *

pathDirPos=os.listdir("review_polarity/txt_sentoken/pos")
pathDirNeg=os.listdir("review_polarity/txt_sentoken/neg")
trainingData,traingLabel,testData,testLabel=Bayes.splitDataSet(pathDirPos,pathDirNeg,0.67)
#print(trainingData,traingLabel)
vocab=Bayes.getVocab(trainingData)
p0A,p1A,p1=Bayes.TrainBayes(trainingData,traingLabel,vocab)
len_testData=len(testData)
print(len(trainingData))
error_count=0
for i in range(len_testData):
    mathVec=Bayes.word2Vec(vocab,testData[i])
    result=Bayes.classifyBayes(mathVec,p0A,p1A,p1)
    if(result!=testLabel[i]):
        error_count+=1
error_rate=error_count/float(len_testData)
print(error_rate)
